﻿using System.Collections.Generic;
using System.Linq;
using Dapper;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.Crm.CommonEntity.Peizh;
using ZilLion.Service.Crm.ModelBase.EntityBase.Cache;

namespace ZilLion.Service.WebInfrastructure.Base
{
    public class ConfigCacheRepository : SqlServerRespository<JltyKzCacheItem>, IConfigCacheRepository
    {
        public ConfigCacheRepository(IDbContext context) : base(context)
        {
        }

        public JltyKzCacheItem GetJltycrmkykztConfigItems()
        {
            JltyKzCacheItem item =new JltyKzCacheItem();
            item.kykzts = this.GetList<Jltycrmkykzt>("select * from jltycrmkykzt").ToList();
            item.kykztslogsn = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='jltycrmkykzt'").GetValueOrDefault();
            return item;
        }

        public int CheckJltycrmkykztItems()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='jltycrmkykzt'").GetValueOrDefault();
            return logsnv2;
        }

        public JltyZklbCacheItem GetJltycrmkyzklbtConfigItems()
        {
            JltyZklbCacheItem item = new JltyZklbCacheItem();
            item.kyzklbts = this.GetList<Jltycrmkyzklbt>("select zklbid,zklbmc,zklbsbm,kzkhsign,zklbqyday from jltycrmkyzklbt").ToList();
            item.kyzklbtslogsn = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='jltycrmkyzklbt'").GetValueOrDefault();
            return item;
        }

        public int CheckJltycrmkyzklbtItems()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='jltycrmkyzklbt'").GetValueOrDefault();
            return logsnv2;
        }

        public ZzinfocsCacheItem GetChargeInfo()
        {
            zzinfo zzinfo = new zzinfo();
            ZzinfocsCacheItem infoc =new ZzinfocsCacheItem();
            DynamicParameters p = CreateDynamicParameters();
            IEnumerable<zzinfo> items = ExecuteProcWithTemptable(zzinfo, "pr_Zengzhl_Query", "#zzinfo", false,
               p);
            infoc.kinfocslogsn = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='cfv4appczbz'").GetValueOrDefault();
            infoc.infocs = items.ToList();
            return infoc;
        }

        public int CheckChargeInfo()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='cfv4appczbz'").GetValueOrDefault();
            return logsnv2;
        }

        public GxcspzCacheItem GetGxcspzCacheItemConfigItems()
        {
            GxcspzCacheItem item = new GxcspzCacheItem();
            item.gxcses = this.GetList<Gxcs>("select * from gongxparamsshengx").ToList();
            item.gxcseslogsn = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='gongxparamsshengx'").GetValueOrDefault();
            return item;
        }

        public int CheckGxcspz()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='gongxparamsshengx'").GetValueOrDefault();
            return logsnv2;
        }

        public ZlfixedlistCacheItem GetZlfixedlistCacheItemConfigItems()
        {
            ZlfixedlistCacheItem item = new ZlfixedlistCacheItem();
            item.Zlfixedlists =
                GetList<Zlfixedlist>("select flid, flsign, flname, flindex, flsn, flstop from zlfixedlist").ToList();
            item.Zlfixedlistlogsn =
                GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='zlfixedlist'").GetValueOrDefault();
            return item;
        }

        public int CheckZlfixedlist()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='zlfixedlist'").GetValueOrDefault();
            return logsnv2;
        }

        public ZlcompanylistCacheItem GetZlcompanylistCacheItem()
        {
            ZlcompanylistCacheItem item = new ZlcompanylistCacheItem();
            item.Zlcompanylists =
                GetList<Zlcompany>("select coid, coab, couserab, cousercode from zlcompany").ToList();
            item.Zlcompanylogsn =
                GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='zlcompany'").GetValueOrDefault();
            return item;
        }

        public int CheckZlcompanylistCacheItem()
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='zlcompany'").GetValueOrDefault();
            return logsnv2;
        }
    }
   

}
